<template>
  <div class="gl_contentBox gl_heightFull">
    <div class="demo-input-suffix gl_searchBox">
      <el-row :gutter="20">
        <el-col :span="4">
          <p>商品状态</p>
          <el-select v-model="IsEnabled" size="mini" @change="getgoodlist()">
            <el-option label="全部" value="" />
            <el-option label="上架" value="OnShelf" />
            <el-option label="下架" value="InStorage" />
          </el-select>
        </el-col>
        <el-col :span="4">
          <p>商品名称</p>
          <el-input v-model="Api_GET_ClubBranchBranchMallDataQO.Filter" placeholder="请输入商城名称" size="mini" clearable @change="getgoodlist()" />
        </el-col>
        <el-col :span="8">
          <el-button type="primary" style="margin-top:25px" size="mini" @click="getgoodlist()">筛选</el-button>
          <el-button type="warning" size="mini" @click="reset()">{{ $t('button.Reset') }}</el-button>
          <el-button type="success" size="mini" @click="gomallData">查看商城数据</el-button>
        </el-col>
      </el-row>
    </div>

    <div style="margin-top:15px">
      <el-table v-loading="tableLoading" class="gl_table_noBorder" size="mini" :data="tableData">
        <el-table-column type="index" label="序号" align="center" width="55" />
        <el-table-column label="商品名称" align="center" prop="name" />
        <el-table-column label="库存" align="center" prop="count" />
        <el-table-column label="销售额" align="center" prop="amount">
          <template slot-scope="{row}">

            {{ parseFloat( row.amount * 100) / 10000 }}
          </template>
        </el-table-column>
        <el-table-column label="创建时间">
          <template slot-scope="{row}">
            <span v-if="row.creationTime">
              {{ row.creationTime | FormatDate('yyyy-MM-dd HH:mm:ss') }}
            </span>
          </template>
        </el-table-column>
        <el-table-column label="创建人" align="center" prop="creatorName" />
        <el-table-column label="状态" align="center">
          <template slot-scope="{row}">
            <span>
              {{ row.productStatusCode === 'OnShelf' ? '上架':'下架' }}
            </span>

          </template>
        </el-table-column>
        <el-table-column label="操作" width="160">
          <template slot-scope="{row}">
            <el-button size="mini" type="text" @click="lookMall(row.id)">查看</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <goods ref="goods" />
    <!-- 分页 -->
    <el-row class="gl_pt_15" style="text-align: right;">
      <el-pagination
        :current-page="Api_GET_ClubBranchBranchMallDataQO.Page"
        :page-size="Api_GET_ClubBranchBranchMallDataQO.MaxResultCount"
        :total="totalPage"
        layout="total,sizes,prev,pager,next,jumper"
        :page-sizes="[10, 20, 30, 40]"
        @size-change="sizeChange"
        @current-change="pageIndexChange"
      />
    </el-row>
  </div>
</template>

<script>
import { mapState, mapActions } from 'vuex';
import { api_GET_ClubBranchBranchMallData } from '@/extend/api/hallswaggerApi/app.js';
import { Api_GET_ClubBranchBranchMallDataQO } from '@/lib/form/hall/swaggerForm';
import goods from './goods.vue';
export default {
  components: {
    goods
  },
  data() {
    return {
      Api_GET_ClubBranchBranchMallDataQO: new Api_GET_ClubBranchBranchMallDataQO(), // 分道馆商城数据
      tableData: [],
      tableLoading: false,
      IsEnabled: '',
      totalPage: 0,
      Array: []
    };
  },
  computed: {
    ...mapState({
      dict: state => state.dict.dict,
      cache: state => state.dict.cache,
      user: state => state.user.currentOU
    })
  },
  created() {
    this.getDict();
    this.getgoodlist();
  },
  methods: {
    ...mapActions({ getDict: 'dict/getDict' }),
    // 获取商品列表
    getgoodlist(page) {
      this.tableLoading = true;
      this.Array = [];
      if (this.IsEnabled !== '') {
        this.Array = [this.IsEnabled];
      } else {
        this.Array = ['OnShelf', 'InStorage'];
      }
      console.log(this.Array);
      this.Api_GET_ClubBranchBranchMallDataQO.Sorting = 'creationTime DESC';
      this.Api_GET_ClubBranchBranchMallDataQO.BranchId = this.$route.query.branchid;
      this.Api_GET_ClubBranchBranchMallDataQO.ProductStatusCodes = this.Array;
      this.Api_GET_ClubBranchBranchMallDataQO.Page = page || 1;
      this.Api_GET_ClubBranchBranchMallDataQO.SkipCount = (this.Api_GET_ClubBranchBranchMallDataQO.Page - 1) * this.Api_GET_ClubBranchBranchMallDataQO.MaxResultCount;
      api_GET_ClubBranchBranchMallData(this.Api_GET_ClubBranchBranchMallDataQO).then(res => {
        this.tableLoading = false;
        this.tableData = res.items;
        this.totalPage = res.totalCount;
      }, error => {
        this.tableLoading = false;
        const _msg = error.error.message || error.message;
        this.$message({ type: 'error', message: _msg });
      });
    },
    lookMall(row) {
      this.$refs.goods.goodid = row;
      this.$refs.goods.dialogVisible = true;
      this.$refs.goods.init();
    },
    gomallData() {
      this.$router.push({ name: 'Goodsdata', query: { branchid: this.$route.query.branchid }});
    },
    // 重置按钮
    reset () {
      this.Api_GET_ClubBranchBranchMallDataQO = new Api_GET_ClubBranchBranchMallDataQO();
      this.IsEnabled = '';
      this.getgoodlist();
    },
    // 分页按钮
    sizeChange(MaxResultCount) {
      this.Api_GET_ClubBranchBranchMallDataQO.MaxResultCount = MaxResultCount;
      this.getgoodlist();
    },
    pageIndexChange(currentPage) {
      this.getgoodlist(currentPage);
    }
  }
};
</script>

<style>

</style>
